#pragma once
#include <rviz_common/panel.hpp>
#include "rviz_custom_plugins/utils/interactive_marker_thread.h"
#include <rviz_common/config.hpp>
#include "rviz_custom_plugins/panels/ui_snapshot_plane_panel.h"
#include "rviz_custom_plugins/utils/bag_map_notifier.h"
#include "rviz_custom_plugins/viewmodels/point_group_model.h"
#include <interactive_markers/interactive_marker_server.hpp>
#include "rviz_custom_plugins/models/point_normal.h"


using rviz_common::Config;
using rviz_custom_plugins::utils::InteractiveMarkerThread;
using rviz_custom_plugins::utils::BagMapNotifier;
using rviz_custom_plugins::viewmodels::PointGroupModel;
using interactive_markers::InteractiveMarkerServer;
using rviz_custom_plugins::models::PointNormal;



namespace rviz_custom_plugins
{

namespace panels
{


class SnapshotPlanePanel : public rviz_common::Panel
{
    Q_OBJECT

public:
    explicit SnapshotPlanePanel(QWidget *parent = nullptr);

    void load(const Config& config) override;

private:

    BagMapNotifier* mapNotifier;

    Ui::snapshotPlanePanel* ui{ nullptr };
    std::shared_ptr<InteractiveMarkerThread> markerThread;

    PointGroupModel* treeModel;

    void addPlaneButtonClicked();
    void removePlaneButtonClicked();

    void removePointButtonClicked();

    void getCurrentIndex(int& l1Row, int& l2Row);

    void addGroupItem(int l1Row, int l2Row, PointNormal point);
    void removeGroup(int l1Row);

private slots:
    void handleMarkerFeedback(InteractiveMarkerServer::FeedbackConstSharedPtr feedback);
    void handleActiveStatusChanged(bool active);

    void handlerMarkersReorder(int l1Row, int l2Row, std::list<InteractiveMarker>& markers);

    void handleMapPointSelected(QString nameSpace, int pclIndex, pcl::PointXYZINormal& point);

    void handleProjectLoaded(QSharedPointer<QVariantMap> projectData);
    void handleProjectSaved(QSharedPointer<QVariantMap> projectData);
    void handleProjectClosed(QSharedPointer<QVariantMap> projectData);

};


}


}
